#ifndef SETTING_H
#define SETTING_H

#include <qstring.h>
#include <OrmBase.h>
#include <QVariantMap>

class Setting : public OrmBase {
    Q_OBJECT
    /**
     * @property id
     * @brief 用户ID属性 - 对外名称为 id，内部存储为 id
     * - 属性名: id (在QML和property()函数中使用)
     * - 成员变量: id (类内部实际存储的变量)
     * - 访问 property("id").toInt(); 对外名称为 id
     * - 设置 setProperty("id", 25);对外名称为 id
     */
    Q_PROPERTY(int id MEMBER id)
    Q_PROPERTY(QString key MEMBER key)
    Q_PROPERTY(QString value MEMBER value)
public:
    int id;
    QString key;
    QString value;



    explicit Setting(QObject *parent = nullptr) : OrmBase(parent) {};
    Setting(const QString &key, const QString &value) : id(0), key(key), value(value) {};
    Setting(const QString &key, const QString &value, QObject *parent = nullptr)
        : OrmBase(parent), id(0),key(key), value(value) {};

    QString tableName() const override { return "setting"; }

    QVariantMap toMap() const override {
        QVariantMap map;
        map["key"] = key;
        map["value"] = value;
        return map;
    }

    void fromMap(const QVariantMap &map) override {
        id = map.value("id").toInt();
        key = map.value("key").toString();
        value = map.value("value").toString();
    }
};

#endif // SETTING_H
